package com.hongding.sealcenter.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * 证书信息
 */
@Getter
public enum SignAlgEnum {
    SM2("SM2", "SM2", "ECDSA", 256),
    RSA("RSA", "RSA2048", "RSA", 2048),
    ;
    private String name;
    private String code;
    private String algorithm;
    private Integer length;

    SignAlgEnum(String code, String name, String algorithm, Integer length) {
        this.name = name;
        this.code = code;
        this.algorithm = algorithm;
        this.length = length;
    }

    public static boolean equalsSM2(String code) {
        return SM2.code.equalsIgnoreCase(code);
    }

    public static boolean equalsRSA(String code) {
        return RSA.code.equalsIgnoreCase(code);
    }

    public static SignAlgEnum getAlgorithmEnum(String code) {
        for (SignAlgEnum algorithmEnum : values()) {
            if (Objects.equals(algorithmEnum.getCode(), code.toUpperCase())) {
                return algorithmEnum;
            }
        }
        throw new RuntimeException("证书类型必须是RSA或者SM2");
    }

}
